//
// Created by leisurexi on 12/6/20.
// syscpy.c
//
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>

#define BUF_SIZE 3

int main(int argc, char *argv[]) {
    int fp1, fp2;
    int len;
    char buf[BUF_SIZE];
    clock_t start, end;


    fp1 = open("/home/leisurexi/Documents/news.txt", O_RDONLY);
    fp2 = open("/home/leisurexi/Documents/cpy.txt", O_WRONLY | O_CREAT | O_TRUNC);

    start = clock();
    while ((len = read(fp1, buf, sizeof(buf))) > 0)
        write(fp2, buf, len);
    end = clock();
    printf("time=%f\n", ((double) end - start));

    close(fp1);
    close(fp2);
    return 0;
}
